﻿$(document).ready(function () {
   
   // test();
    
})

function test()
{
    var where = { keyword: "", msgType: "all", currentPage: 1, pageSize: 15 };
    $.post("/Command/GetPageList", where, function (result1) {
       
        //返回字符串，要转换成json对象
        var result = eval('(' + result1 + ')')
        // alert(result.total);
        var list = "";
        $.each(result.data, function (i, e) {
            var line = "<li>" + e.Keyword + "</li>";
            list = list + line;
        });
        $("#ulData").html(list);
    },"json");
}

function GetData()
{
    var AjaxPager = {
        Url: "",
        PageSize: 10,
        CurrentPageIndex: 1,
        PageCount: 0,
        Where: {},
        SetPager: function (url, pagesize, where) {
            this.Url = url;
            this.PageSize = pagesize;
            this.Where = where;
        },
        LoadPageData: function (pageIndex) {
            //检查页码范围
            if (pageIndex <= 0) {   //首页
                this.CurrentPageIndex = 1;
            }
            else if (this.PageCount > 0 && pageIndex > this.PageCount) {
                this.CurrentPageIndex = this.PageCount;
            }
            else {
                this.CurrentPageIndex = pageIndex;
            }

            // 在查询条件参数中，追加分页大小和当前页参数
            var pageParams = { currentPage: pageIndex, pageSize: this.PageSize }
            $.extend(this.Where, pageParams);
            //请求分页数据 
            $.post(this.Url, this.Where, function (result) {
                AjaxPager.PageCount = Math.ceil(result.total / AjaxPager.PageSize);
                AjaxPager.ShowPage(result.data);

                //首页和末页
                $("#btnFirst").click(function () { LoadPageData(1); });
                $("#btnLast").click(function () { LoadPageData(AjaxPager.PageCount) });
            });

            //显示分页样式
            $("#CurrentPage").html("当前页:" + this.CurrentPageIndex + "/" + (this.PageCount == 0 ? 1 : this.PageCount));
            $("#PageSel").val(this.CurrentPage);
        },
        ShowPage: function (data) {

        }
    };

    AjaxPager.SetPager("/Command/GetPageList", 10, { keyword: "", msgType: "all" });
    AjaxPager.LoadPageData(1);
    AjaxPager.ShowPage = show;
}

function show(result)
{
    $.each(result, function (i, n) {
        alert(i);
    });
}